// Copyright 2012 Google Inc. All Rights Reserved.
// Author: bqe@google.com (Burak Emir)

// Copyright 2012 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef SRC_WORKER_POOL_H_
#define SRC_WORKER_POOL_H_

#include <pthread.h>
#include "worker.h"

namespace seven_summits {

// Fixed-size pool of Worker instances.
class WorkerPool {
 public:
  explicit WorkerPool(int num_workers, WorkerFactory* factory);
  ~WorkerPool();

  // Spins up the threads.
  void Init();

  // Returns the next worker, in a round-robin fashion.
  Worker* GetWorker();

 private:
  int num_workers_;
  Worker** workers_;
  int next_worker_;
  pthread_mutex_t mutex_;
};

}  // namespace seven_summits

#endif  // SRC_WORKER_POOL_H_
